sym = input()
n = int(input())
tmp_sym = ''
count = 0
max_el = 0
for i in range(n):
    a = input()
    if a == sym and tmp_sym == sym:
        count += 1
    elif tmp_sym != sym:
        count=0

    tmp_sym = sym
    if max_el < count:
        max_el = count

print(max_el)